package com.florent3.shapeofview.sample.slice;

import com.florent3.shapeofview.sample.ResourceTable;
import com.github.florent37.shapeofview.shapes.CutCornerView;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * MainAbilitySlice
 *
 * @since 2021 -07-26
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");
    private CutCornerView shapes, shrine, anim, jackman,
        star_wars, star_wars_animated, round, star,
        dottedEdges;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
        inListener();


    }

    public void initView() {
        shapes = (CutCornerView) findComponentById(ResourceTable.Id_shapes);
        shrine = (CutCornerView) findComponentById(ResourceTable.Id_shrine);
        anim = (CutCornerView) findComponentById(ResourceTable.Id_anim);
        jackman = (CutCornerView) findComponentById(ResourceTable.Id_jackman);
        star_wars = (CutCornerView) findComponentById(ResourceTable.Id_star_wars);
        star_wars_animated = (CutCornerView) findComponentById(ResourceTable.Id_star_wars_animated);
        round = (CutCornerView) findComponentById(ResourceTable.Id_round);
        star = (CutCornerView) findComponentById(ResourceTable.Id_star);
        dottedEdges = (CutCornerView) findComponentById(ResourceTable.Id_dottedEdges);
    }

    public void inListener() {
        shapes.setClickedListener(this);
        shrine.setClickedListener(this);
        anim.setClickedListener(this);
        jackman.setClickedListener(this);
        star_wars.setClickedListener(this);
        star_wars_animated.setClickedListener(this);
        round.setClickedListener(this);
        star.setClickedListener(this);
        dottedEdges.setClickedListener(this);

    }

    /**
     * inTents
     *
     * @param AbilityName 1
     */
    public void inTents(String AbilityName) {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder().withDeviceId("")
            .withBundleName(getBundleName())
            .withAbilityName(getBundleName() + "." + AbilityName).build();
        intent.setOperation(operation);
        startAbility(intent);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_shapes:
                inTents("ShapeOfViewStarAbility");
                break;
            case ResourceTable.Id_shrine:
                inTents("MaterialDesignShrineAbility");
                break;
            case ResourceTable.Id_anim:
                inTents("ShapeOfViewAnimationAbility");
                break;
            case ResourceTable.Id_jackman:
                inTents("JackmanAbility");
                break;
            case ResourceTable.Id_star_wars:
                inTents("StarWarsAbility");
                break;
            case ResourceTable.Id_star_wars_animated:
                inTents("ShapeOfViewStarAnimatedAbility");
                break;
            case ResourceTable.Id_round:
                inTents("ShapeOfViewRoundAbility");
                break;
            case ResourceTable.Id_star:
                inTents("ShapeOfViewStarAbility");
                break;
            case ResourceTable.Id_dottedEdges:
                inTents("DottedEdgesAbility");
                break;

        }
    }
}
